import { actionTypes } from '../actions/thunk'

const initState = {
    newsType: null,
    newsList: null,
    error: null
}

const reducer = (state = initState, action) => {
    switch (action.type) {
        case actionTypes.REQUEST:
            return { ...state, isFetching: true }
        case actionTypes.NEWSTYPE_SUCCESS:
            return { ...state, newsType: action.payload, isFetching: false }
        case actionTypes.NEWSLIST_SUCCESS:
            state.newsList = []
            return { ...state, newsList: action.payload, isFetching: false }
        case actionTypes.ERROR:
            return { ...state, isFetching: false, error: action.error }
        default:
            return state
    }
}

export default reducer
